<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="照片" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'stPhoto', validatorRules.stPhoto]" placeholder="请输入照片"></a-input>
        </a-form-item>
        <a-form-item label="学生姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'stName', validatorRules.stName]" placeholder="请输入学生姓名"></a-input>
        </a-form-item>
        <a-form-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['sex']" :trigger-change="true" dictCode="sex" placeholder="请选择性别"/>
        </a-form-item>
        <a-form-item label="学号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'studentId', validatorRules.studentId]" placeholder="请输入学号"></a-input>
        </a-form-item>
        <a-form-item label="联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'phone', validatorRules.phone]" placeholder="请输入联系方式"></a-input>
        </a-form-item>
        <a-form-item label="学院" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-select-depart v-decorator="['college']" :trigger-change="true" @change="getcollect"/>
        </a-form-item>
        <a-form-item label="年级" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['fieldTwo']" :trigger-change="true" dictCode="grade" placeholder="请选择年级"/>
        </a-form-item>
        <a-form-item label="专业" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <!--<j-dict-select-tag type="list" v-decorator="['profession']" :trigger-change="true" dictCode="st_profession,profession,id" placeholder="请选择专业"/>-->
          <a-select v-decorator="['profession']" @change="getclass">
            <a-select-option :value="item.id" v-for="item in collegelist">{{item.profession}}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="班级" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <!--<j-dict-select-tag type="list" v-decorator="['stClass']" :trigger-change="true" dictCode="st_class,classes,id" placeholder="请选择班级"/>-->
          <a-select v-decorator="['stClass']">
            <a-select-option :value="item.id" v-for="item in classlist">{{item.classes}}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="宿舍" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'dormRoom', validatorRules.dormRoom]" placeholder="请输入宿舍"></a-input>
        </a-form-item>
        <a-form-item label="政治面貌" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['face']" :trigger-change="true" dictCode="face" placeholder="请选择政治面貌"/>
        </a-form-item>
        <a-form-item label="家庭困难级别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['difficult']" :trigger-change="true" dictCode="difficult" placeholder="请选择家庭困难级别"/>
        </a-form-item>
        <a-form-item label="单亲孤儿" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['single']" :trigger-change="true" dictCode="single" placeholder="请选择单亲孤儿"/>
        </a-form-item>
        <a-form-item label="心理情况" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['psychological']" :trigger-change="true" dictCode="psychological" placeholder="请选择心理情况"/>
        </a-form-item>
        <a-form-item label="处分" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['punish']" :trigger-change="true" dictCode="punish" placeholder="请选择处分"/>
        </a-form-item>
        <a-form-item label="学业预警" :labelCol="labelCol" :wrapperCol="wrapperCol">
        <j-dict-select-tag type="list" v-decorator="['academicWarning']" :trigger-change="true" dictCode="whether" placeholder="请选择学业预警"/>
      </a-form-item>
        <a-form-item label="延迟毕业" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['delayedGraduation']" :trigger-change="true" dictCode="delayedGraduation" placeholder="请选择延迟毕业"/>
        </a-form-item>
        <a-form-item label="毕业就业率" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['graduation']" :trigger-change="true" dictCode="graduation" placeholder="请选择毕业就业率"/>
        </a-form-item>
        <a-form-item label="民族" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['nationality']" :trigger-change="true" dictCode="nation" placeholder="请选择民族"/>
        </a-form-item>
        <a-form-item label="省" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-tree-select
            v-decorator="[ 'province', validatorRules.province]"
            placeholder="请选择菜单"
            dict="st_areas,areaname,id"
            pidField="areas"
            pidValue=""
          />
        </a-form-item>
        <a-form-item label="市" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-tree-select
            v-decorator="[ 'city', validatorRules.city]"
            placeholder="请选择菜单"
            dict="st_areas,areaname,id"
            pidField="areas"
            pidValue=""/>
        </a-form-item>
        <a-form-item label="区/县" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-tree-select
            v-decorator="[ 'area', validatorRules.area]"
            placeholder="请选择菜单"
            dict="st_areas,areaname,id"
            pidField="areas"
            pidValue=""
          />
        </a-form-item>
        <a-form-item label="家庭地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'familyAddress', validatorRules.familyAddress]" placeholder="请输入家庭地址"></a-input>
        </a-form-item>
        <a-form-item label="家长1" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'parentOne', validatorRules.parentOne]" placeholder="请输入家长1"></a-input>
        </a-form-item>
        <a-form-item label="家长2" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'parentTwo', validatorRules.parentTwo]" placeholder="请输入家长2"></a-input>
        </a-form-item>
        <a-form-item label="家长电话1" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'phoneOne', validatorRules.phoneOne]" placeholder="请输入家长电话1"></a-input>
        </a-form-item>
        <a-form-item label="家长电话2" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'phoneTwo', validatorRules.phoneTwo]" placeholder="请输入家长电话2"></a-input>
        </a-form-item>
        <a-form-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['status']" :trigger-change="true" dictCode="st_status" placeholder="请选择状态"/>
        </a-form-item>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>

  import { httpAction,getAction} from '@/api/manage'
  import pick from 'lodash.pick'
  import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  import JTreeSelect from '@/components/jeecg/JTreeSelect'

  export default {
    name: "StStudentModal",
    components: {
      JSelectDepart,
      JDictSelectTag,JTreeSelect
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        collegelist:[],
        classlist:[],
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        stPhoto:{},
        stName:{rules: [{ required: true, message: '请输入学生姓名!' }]},
        sex:{rules: [{ required: true, message: '请输入性别!' }]},
        studentId:{rules: [{ required: true, message: '请输入学号!' }]},
        phone:{rules: [{ required: true, message: '请输入联系方式!' }]},
        college:{rules: [{ required: true, message: '请输入学院!' }]},
        fieldTwo:{rules: [{ required: true, message: '请输入年级!' }]},
        profession:{rules: [{ required: true, message: '请输入专业!' }]},
        stClass:{rules: [{ required: true, message: '请输入班级!' }]},
        dormRoom:{rules: [{ required: true, message: '请输入宿舍!' }]},
        face:{rules: [{ required: true, message: '请输入政治面貌!' }]},
        difficult:{rules: [{ required: true, message: '请输入家庭困难级别!' }]},
        single:{rules: [{ required: true, message: '请输入单亲孤儿!' }]},
        psychological:{rules: [{ required: true, message: '请输入心理情况!' }]},
        punish:{rules: [{ required: true, message: '请输入处分!' }]},
        academicWarning:{rules: [{ required: true, message: '请输入学业预警!' }]},
        delayedGraduation:{rules: [{ required: true, message: '请输入延迟毕业!' }]},
        graduation:{rules: [{ required: true, message: '请输入毕业就业率!' }]},
        nationality:{rules: [{ required: true, message: '请输入民族!' }]},
        province:{},
        city:{},
        area:{},

        familyAddress:{rules: [{ required: true, message: '请输入家庭地址!' }]},
        parentOne:{rules: [{ required: true, message: '请输入家长1!' }]},
        parentTwo:{rules: [{ required: true, message: '请输入家长2!' }]},
        phoneOne:{rules: [{ required: true, message: '请输入家长电话1!' }]},
        phoneTwo:{rules: [{ required: true, message: '请输入家长电话2!' }]},
        status:{rules: [{ required: true, message: '请输入状态!' }]},
        },
        url: {
          add: "/st/stStudent/add",
          edit: "/st/stStudent/edit",
        }

      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'stPhoto','stName','sex','studentId','phone','college','fieldTwo','profession','stClass','dormRoom','face','difficult','single','psychological','punish','academicWarning','delayedGraduation','graduation','nationality','province','city','area','familyAddress','parentOne','parentTwo','phoneOne','phoneTwo','status'))
        })
         this.getcollect(this.model.college)
         this.getclass(this.model.profession)
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }

        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'stPhoto','stName','sex','studentId','phone','college','fieldTwo','profession','stClass','dormRoom','face','difficult','single','psychological','punish','academicWarning','delayedGraduation','graduation','nationality','province','city','area','familyAddress','parentOne','parentTwo','phoneOne','phoneTwo','status'))
      },
    //  学院获取专业
      getcollect(data){
        var that=this
        getAction('/st/mobile/getSchoolProfession',{college:data}).then(res=>{
          if(res.success){
            that.collegelist=res.result.records
          }
        })
      },
    //  专业获取班级
      getclass(data){
        var that=this
        getAction('/st/mobile/getSchoolClass',{profession:data}).then(res=>{
          if(res.success){
            that.classlist=res.result.records
          }
        })
      }


    }
  }
</script>